﻿

namespace KingerRobot.MexicoSailunMES.SpiService;

internal class MiddleMesServiceImpl : IMiddleMesService
{    // 请料
    public List<TcmInfo> GetRequestMaterialInfos()
    {
        var db = Db.Default;

        var reqAndSpecs = db.TcmGtReqs
            .Where(t => t.GtReq == "Y"|| t.LdGt ==  "N"|| t.CvGt ==  "N")
            .Join(db.TcmGtSpecs, f => f.TcmNo, s => s.TcmDir, (f, s) => new 
            {
                Req = f,
                Spec = s,
            }).ToList();

        List<TcmInfo> infos = new List<TcmInfo>();

        foreach (var reqAndSpec in reqAndSpecs)
        {
            infos.Add(TcmInfo.Create(reqAndSpec.Spec, reqAndSpec.Req));
        }
        return infos.OrderBy(f => f.REQ_REG_DT).ToList();
    }
}
